import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  }, {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  }, {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'Dashboard', icon: 'dashboard' }
    }]
  }, {
    path: '/sys',
    component: Layout,
    redirect: '/sys/user',
    name: '系统管理',
    meta: { title: '系统管理', icon: 'el-icon-s-tools' },
    children: [
      {
        path: 'user',
        name: '系统用户管理',
        component: () => import('@/views/system/SysUser'),
        meta: { title: '系统用户管理', icon: 'el-icon-user-solid' }
      }, {
        path: 'role',
        name: 'ROLE',
        component: () => import('@/views/system/SysRole'),
        meta: { title: '角色管理', icon: 'el-icon-s-custom' }
      }, {
        path: 'menu',
        name: 'MENU',
        component: () => import('@/views/system/SysMenu'),
        meta: { title: '菜单管理', icon: 'el-icon-menu' }
      }, {
        path: 'dict',
        name: '系统参数管理',
        component: () => import('@/views/system/SysDict'),
        meta: { title: '系统参数管理', icon: 'el-icon-s-operation' }
      }
    ]
  },
  {
    path: 'external-link',
    component: Layout,
    children: [
      {
        path: 'https://gitee.com/colaiven',
        meta: { title: 'External Link', icon: 'link' }
      }
    ]
  },

  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher
}

export default router
